package com.zzh.model.prototype;

import androidx.annotation.NonNull;

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-11-14
 * @desc 原型模式
 */
public class PrototypeDemo {

    private PrototypeDemo() {
    }

    private static class PrototypeDemoHolder {
        static PrototypeDemo prototypeDemo = new PrototypeDemo();
    }

    public static PrototypeDemo getInstance() {
        return PrototypeDemoHolder.prototypeDemo;
    }


    public DataBean config(String name, String value) {
        DataBean dataBean = new DataBean();
        dataBean.setName(name);
        dataBean.setValue(value);
        return dataBean;
    }

    public DataBean cloneDataBean(DataBean dataBean) {
        try {
            return dataBean.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static class DataBean implements Cloneable {

        private String name;
        private String value;

        public String getName() {
            return name;
        }

        public String getValue() {
            return value;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setValue(String value) {
            this.value = value;
        }

        @Override
        public String toString() {
            return "DataBean{" +
                    "name='" + name + '\'' +
                    ", value='" + value + '\'' +
                    '}';
        }

        @NonNull
        @Override
        protected DataBean clone() throws CloneNotSupportedException {
            return (DataBean) super.clone();
        }
    }

}
